/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CDialogoSelecionarBd.java
 *
 * Created on 27/06/2010, 11:28:00
 */

package rpt.bd.cenario;

import javax.swing.JPanel;

/**
 *
 * @author Roberto
 */
public class CDialogoSelecionarBd extends javax.swing.JPanel {


    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    /** Creates new form CDialogoBd */

    JPanel fDialogoCentral;
    CCenarioBd fCenarioBd;
    CPersistenciaBd fPertinenciaBd;
    CJanelaSelecionarBd fDialogo;

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    /** Creates new form CDialogoSelecionarBd */
    public CDialogoSelecionarBd(CCenarioBd aCenarioBd, CJanelaSelecionarBd aDialogo) {
        initComponents();
        fCenarioBd = aCenarioBd;
        fDialogo = aDialogo;
        fPertinenciaBd = fCenarioBd.getPertinenciaBd();
        HabilitarBotoes(true,true);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public int AdicionarDialogoCentral(final JPanel aDialogoCentral) {
       fDialogoCentral = aDialogoCentral;
       PainelCentral().add(fDialogoCentral);
       return 1;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CPersistenciaBd getPertinenciaBd() {
        return fPertinenciaBd;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JPanel PainelCentral() {
       return swPnlCentral;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    private void HabilitarBotoes(
            final boolean aSelecionar, final boolean aCancelar) {
        swBtnSelecionar.setEnabled(aSelecionar);
        swBtnCancelar.setEnabled(aCancelar);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    private void setCores() {
        CRegistroBd r = null;
        final CGradeBdCenario g = fCenarioBd.getGrade();
        if (g != null) {
            r = g.getRegistroBdAtual();
            if (r != null) r.setCoresCamposRegistroBd();
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        swPnlTopo = new javax.swing.JPanel();
        swPnlCentral = new javax.swing.JPanel();
        swPnlFundo = new javax.swing.JPanel();
        swBtnSelecionar = new javax.swing.JButton();
        swBtnCancelar = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        swPnlTopo.setBackground(new java.awt.Color(230, 230, 230));

        javax.swing.GroupLayout swPnlTopoLayout = new javax.swing.GroupLayout(swPnlTopo);
        swPnlTopo.setLayout(swPnlTopoLayout);
        swPnlTopoLayout.setHorizontalGroup(
            swPnlTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        swPnlTopoLayout.setVerticalGroup(
            swPnlTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 33, Short.MAX_VALUE)
        );

        add(swPnlTopo, java.awt.BorderLayout.NORTH);

        swPnlCentral.setLayout(new java.awt.BorderLayout());
        add(swPnlCentral, java.awt.BorderLayout.CENTER);

        swPnlFundo.setBackground(new java.awt.Color(230, 230, 230));

        swBtnSelecionar.setText("Selecionar");
        swBtnSelecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                swBtnSelecionarActionPerformed(evt);
            }
        });

        swBtnCancelar.setText("Cancelar");
        swBtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                swBtnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout swPnlFundoLayout = new javax.swing.GroupLayout(swPnlFundo);
        swPnlFundo.setLayout(swPnlFundoLayout);
        swPnlFundoLayout.setHorizontalGroup(
            swPnlFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlFundoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(swBtnSelecionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(swBtnCancelar)
                .addContainerGap(228, Short.MAX_VALUE))
        );
        swPnlFundoLayout.setVerticalGroup(
            swPnlFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(swPnlFundoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(swPnlFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(swBtnSelecionar)
                    .addComponent(swBtnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(swPnlFundo, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void swBtnSelecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_swBtnSelecionarActionPerformed
        fDialogo.atribuirRegistroBd(fPertinenciaBd.getConjuntoDadosBd().getRegistroBdAtual());
        fDialogo.ok();
}//GEN-LAST:event_swBtnSelecionarActionPerformed

    private void swBtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_swBtnCancelarActionPerformed
        fDialogo.cancel();
}//GEN-LAST:event_swBtnCancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton swBtnCancelar;
    private javax.swing.JButton swBtnSelecionar;
    private javax.swing.JPanel swPnlCentral;
    private javax.swing.JPanel swPnlFundo;
    private javax.swing.JPanel swPnlTopo;
    // End of variables declaration//GEN-END:variables

}
